package cn.ruleengine.web.function;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import cn.ruleengine.core.annotation.Executor;
import cn.ruleengine.core.annotation.Function;
import cn.ruleengine.core.annotation.Param;
import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.util.*;

/**
 * 判断阴阳性结果
 */
@Function
public class YinYangJudgeFunction {

    @Executor
    public String executor(@Param(value = "jsonString") String json) {
        List<YinYangParam> list = JSONUtil.toList(JSONUtil.parseArray(json), YinYangParam.class);
        String currentValue = list.get(0).getValue();
        List<String> valueList = new ArrayList<>();
        List<YinYangRes> res = new ArrayList<>();
        if(currentValue.contains("阴")){
            valueList.addAll(Arrays.asList("阴性","弱阴性"));
        }else{
            valueList.addAll(Arrays.asList("阳性","弱阳性"));
        }
        for (YinYangParam yangParam : list) {
            if(!valueList.contains(yangParam.getOldValue())){
                YinYangRes item = new YinYangRes();
                item.setId(yangParam.getId());
                item.setValue(yangParam.getOldValue());
                res.add(item);
            }
        }
        return CollectionUtil.isEmpty(res) ? "" : JSON.toJSONString(res);
    }

    @Data
    public static class YinYangParam{

        private String value;

        private Long id;

        private String oldValue;

    }

    @Data
    public static class YinYangRes{

        private Long id;

        private String value;

    }
}
